
var reqHandlerPassword;
var valorObjetivo;
var codigorc;
var codigocuenta;
var particion;
var email;
var codigoFlota;
var aliasString;
var codigoDealer;

function validarLogin()
{
		valorObjetivo = document.forms[0].objetivo.value;
 		codigorc = document.forms[0].codigorc.value;
 		codigocuenta = document.forms[0].codigocuenta.value;
 		particion = document.forms[0].particion.value;
 		email = document.forms[0].email.value;
 		codigoFlota = document.forms[0].codigoFlota.value;
 		aliasString = document.forms[0].aliasString.value;
		codigoDealer = document.forms[0].codigoDealer.value;
 		
 		if ( (valorObjetivo == 1 && (codigorc.length==0 || codigocuenta.length==0 || particion.length==0)) ||
			 (valorObjetivo == 2 && (codigorc.length==0 || codigocuenta.length==0 )) ||
 		     (valorObjetivo == 3 && codigoFlota.length == 0) ||
 		     (valorObjetivo == 4 && aliasString.length == 0) ||
			 (valorObjetivo == 5 && codigoDealer.length == 0) ||
 		     (email.length == 0) )
 		{ 
    		alert("Los campos no pueden estar vacios!");
 			return false;
 		}
 		if (valorObjetivo != 3 && isNaN(particion))
 		{
  			alert("El campo PARTICION debe ser un numero");
  			return false;
 		}
 		return true;
}
function getNewPassword(){				
		if (validarLogin()){
			var addParams = "";
			addParams += "COMMAND=FORGOTPASS";
			addParams += "&OBJETIVO=" + valorObjetivo;
			addParams += "&CODIGORC=" + codigorc;
			addParams += "&CODIGOCUENTA=" + codigocuenta;
			addParams += "&PARTICION=" + particion;
			addParams += "&EMAIL=" + email;
			addParams += "&CODIGOFLOTA=" + codigoFlota;
			addParams += "&CODIGODEALER=" + codigoDealer;
			addParams += "&ALIASSTRING=" + aliasString;
    			if (msie) 
            			reqHandlerPassword = new ActiveXObject("Microsoft.XMLHTTP");
        		else
            			reqHandlerPassword = new XMLHttpRequest();
            		reqHandlerPassword.onreadystatechange = OnReadyStateGetNewPassword;    
            		reqHandlerPassword.open("POST", "sections/queryConfig.php", true);
            		reqHandlerPassword.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	    		reqHandlerPassword.send(addParams);
		}
}
	
function OnReadyStateGetNewPassword(){
		ready = reqHandlerPassword.readyState;
		if (ready == 4) {
			if (reqHandlerPassword.responseText != 'undefined') {	
				errorClass = reqHandlerPassword.responseText.parseJSON();
				if (parseInt(errorClass[0].id)!=0)
					location.href = 'msgscreens/msg_sendingMail.php?codeEmail='+ errorClass[0].id;
				else
					location.href = 'welcome.php?error=' + errorClass[0].errorCode;
			}
		}
}
	

function showDiv(divId) {
  		document.getElementById(divId).style.display = "block";
}
 
	
function hideDiv(divId) {
  		document.getElementById(divId).style.display = "none";
}	